package com.thread.thread.CountDownLatch;

import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
import java.util.stream.IntStream;
//countDownLatch 模仿join效果实现
public class CountDownLatchTest {
	public static void main(String[] args) throws  Exception {
		CountDownLatch countDownLatch=new CountDownLatch(10);
		long start=System.currentTimeMillis();
		Thread[] threads=new Thread[10];
		IntStream.range(0,threads.length).forEach(i->{
			threads[i]=new Thread(()->{
				try {
					Thread.sleep(1000);
					countDownLatch.countDown();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println("111");
			});

		});
		Arrays.asList(threads).forEach(thread -> {
			thread.start();
		});
		countDownLatch.await();
		long end=System.currentTimeMillis();

		System.out.println("执行时间"+(end-start));

	}

}
